[deps.host]
gcc4

[mirrors]
http://www.etalabs.net/musl/releases/musl-1.1.3.tar.gz
http://www.musl-libc.org/releases/musl-1.1.3.tar.gz

[main]
filesize=844982
sha512=c580c700d609eced15dc398ff6dcbc2e38fab24eaa5ea80a58c3d41d9f749579cce328bbad149f2b5975533d6ec051e6cc08be3bea4d65e143fc850745bf24c2

[build]
patch -p1 < "$K"/musl-1.1.3-mips-regression.patch || exit 1
./configure --prefix=$butch_prefix --syslibdir=$butch_prefix/lib || exit 1
if [ "$A" = "powerpc" ] ; then
cat << EOF >> config.mak
LDFLAGS += -Wl,--secure-plt
CFLAGS += -msecure-plt
EOF
fi

# enable debug libc when DEBUGBUILD is set
[ ! -z "$DEBUGBUILD" ] && echo "CFLAGS += -O0 -g" >> config.mak
[ ! -z "$DEBUGBUILD" ] && echo "CFLAGS_ALL_SHARED += -O0 -g" >> config.mak

make -j$MAKE_THREADS || exit 1
make DESTDIR="$butch_install_dir" install || exit 1

[ "$butch_prefix" = "/" ] && butch_prefix=
dest=$butch_install_dir$butch_prefix
mkdir -p "$dest"/bin
ln -sf  ../lib/libc.so "$dest"/bin/ldd

musl_gcc="$dest/bin/musl-gcc"

cp "$K/musl-gcc" "$musl_gcc"
chmod +x "$musl_gcc"
sed -i "s,AAAA,$A," "$musl_gcc"
sed -i "s,PPPP,$butch_prefix," "$musl_gcc"

#create dynlinker path file which only contains /lib
#this should speed up dynamic linker path search
mkdir -p "$dest"/etc
printf "%s\n" "$butch_prefix"/lib > "$dest"/etc/ld-musl-$A.path
